package com.practice.httputils.fegin;

import org.springframework.cloud.openfeign.FeignClientBuilder;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

/**
 * @Description : 工厂模式，用来生成动态客户端
 * @Version : V1.0.0
 * @Date : 2023/1/10 17:12
 */
@Component
public class DynamicFeignClientFactory {

    private final FeignClientBuilder feignClientBuilder;

    public DynamicFeignClientFactory(ApplicationContext applicationContext) {
        this.feignClientBuilder = new FeignClientBuilder(applicationContext);
    }

    public DynamicService getFeignClient(final Class<DynamicService> type, String serviceId) {
        return this.feignClientBuilder.forType(type, serviceId).build();
    }
}
